package ciyuanwutuobang.Core;

import ciyuanwutuobang.Entity.PlayerInfo;
import ciyuanwutuobang.MainClass;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.IOException;

public class KickCountManager {
    private File dataFile;
    private YamlConfiguration config;

    public void load() {
        this.dataFile = new File(MainClass.self.getDataFolder(), "KickCount.yml");

        try {
            if (!dataFile.exists()) {
                dataFile.createNewFile();
            }
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        this.config = YamlConfiguration.loadConfiguration(dataFile);
    }

    public boolean save() {
        try {
            this.config.save(this.dataFile);
            return true;
        } catch (IOException var2) {
            var2.printStackTrace();
            return false;
        }
    }

    public void setKickCount(PlayerInfo playerInfo) {
        if (playerInfo.player!=null) {
            this.config.set(playerInfo.player.getName(),playerInfo.beenKickCount);
        }
        this.save();
    }

    public int getKickCount(Player player) {
        this.load();
        this.config.addDefault(player.getName(),0);
        return this.config.getInt(player.getName());
    }
}
